package com.cxs.pastboardtest2.slice;

import com.cxs.pastboardtest2.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.miscservices.pasteboard.PasteData;
import ohos.miscservices.pasteboard.SystemPasteboard;

public class MainAbilitySlice extends AbilitySlice {

    SystemPasteboard pasteboard;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        pasteboard = SystemPasteboard.getSystemPasteboard(this);


        findComponentById(ResourceTable.Id_text_helloworld)
                .setClickedListener(c -> {
                    PasteData pasteData = pasteboard.getPasteData();
                    try {
                        CharSequence primaryText = pasteData.getPrimaryText();
                        System.out.println(primaryText);
                    } catch (Exception e) {
                        System.out.println("error");
                        System.out.println(e.getMessage());
                        e.printStackTrace();
                    }
                });

    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
